<?php

namespace app\modules\setting\configs\office;

use app\common\enum\ConfigEnum;
use app\common\enum\EtcOfficeProductSelected_SendStatusEnum;
use sookie\excel\SaveExcel;
use yii\db\ActiveRecord;
use sookie\react\handlers\UrlHandler;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use app\modules\setting\models\seller\EtcOfficeProductSelected;
use sookie\bootstraps\handlers\AuthChecker;

/**
 * Class TestConfig
 * @package sookie\react\configs
 * app\modules\setting\configs\seller\SelectedConfig 模型的配置类
 */
class SelectedConfig{

    /**
     * @return array
     * 获取搜索表单配置
     */
    public static function getSearchConfig(){
        return [
            [
                "component" => "FormInput",
                "field" => "code",
                "label" => "选品ID",
                "placeholder" => "选品ID",
                "allowClear" => true,
            ],

        ];
    }

    /**
     * @return array
     * 获取表格的操作
     */
    public static function getTableActions(){
        return  [
        ];
    }

    /**
     * @return array
     * 获取表格行的操作
     * [] 表示要id, ["*"] 表示要一行记录,参数名record, ["id"] 指定需要的参数 ， selected_ids 表示需要所有选择的id
     * configParamsField 规定请求的时候带上数据行中的那些参数，只需要字段名
     */
    public static function getTableRowAction(){
        return [
            [
                "actionType" => "CONFIRM",
                "config" => [
                    "footer" => true,
                    "title" => "签收样品",
                    "content" => "点击【确定】签收当前样品"
                ],
                "method" => "post",
                "configUri" => UrlHandler::toAction("office/selected","update"),
                "auth" => AuthChecker::doPermissionCheck("office/selected","update"),
                "configParamsField" => ["id"],
                "label" => "签收",
                ConfigEnum::CALLBACK => function($item,$config){
                    $send_status = ArrayHelper::getValue($item,'send_status');
                    if($send_status == EtcOfficeProductSelected_SendStatusEnum::DONE){
                        $label = $config['label'];
                    }else{
                        $label = EtcOfficeProductSelected_SendStatusEnum::getMsg($send_status);
                    }
                    return [
                        'label' =>  $config['label'],
                        'new_label' => $label,
                        'show' => true,
                    ];
                }
            ],
        ];
    }

    /**
     * @return array
     * 获取表格配置
     */
    public static function getTableConfig(){
        return [
            "rowKey" => "id",
            "columns" => [
                [
                    "title" => "选品ID",
                    "dataIndex" => "code",
                    "sorter" => true,
                    "key" => "code",
                    "format" => "text",
                ],
                [
                    "title" => "产品",
                    "dataIndex" => "product_id",
                    "sorter" => true,
                    "key" => "product_id",
                    "format" => "raw",
                ],
                [
                    "title" => "申请时间",
                    "dataIndex" => "apply_time",
                    "sorter" => true,
                    "key" => "apply_time",
                    "format" => "text",
                ],
                [
                    "title" => "发货状态",
                    "dataIndex" => "send_status",
                    "sorter" => true,
                    "key" => "send_status",
                    "format" => "text",
                ],
                [
                    "title" => "发货时间",
                    "dataIndex" => "send_time",
                    "sorter" => true,
                    "key" => "send_time",
                    "format" => "text",
                ],
                [
                    "title" => "发样数量",
                    "dataIndex" => "send_sample_num",
                    "sorter" => true,
                    "key" => "send_sample_num",
                    "format" => "text",
                ],
                [
                    "title" => "发货地址",
                    "dataIndex" => "send_sample_address_id",
                    "sorter" => true,
                    "key" => "send_sample_address_id",
                    "format" => "text",
                ],
                [
                    "title" => "发货单号",
                    "dataIndex" => "send_code",
                    "sorter" => true,
                    "key" => "send_code",
                    "format" => "text",
                ],
                [
                    "title" => "拍摄状态",
                    "dataIndex" => "video_status",
                    "sorter" => true,
                    "key" => "video_status",
                    "format" => "text",
                ],
            ],
            "actions" => self::getTableRowAction()
        ];
    }

    /**
     * 首页配置
     */
    public static function configIndex(){
        return [
            //搜索表单配置
            "searchConfig" => self::getSearchConfig(),
            // 操作配置 configParams 规定请求的时候带上那些参数
            "actionDivConfig" => self::getTableActions(),
            //表格配置
            "tableConfig" => self::getTableConfig(),
        ];
    }

}

